/*
    Copyright (c) 2011 Marcus Schwartz.  All rights reserved.
 
    This file is part of NetObjects-Arduino.

    NetObjects-Arduino is free software: you can redistribute it and/or 
    modify it under the terms of the GNU Lesser General Public License as 
    published by the Free Software Foundation, either version 3 of the 
    License, or (at your option) any later version.

    NetObjects-Arduino is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public 
    License along with NetObjects-Arduino.  If not, see 
    <http://www.gnu.org/licenses/>.
 */

#include "Wire.h"
#include "WiiChuck.h"
#include <NetObjects.h>
#include <XBee.h>

#define XBEE_BAUD 19200 // zbee factory default is 9600

WiiChuck chuck;
NetObjectsControl net;
TwoButtonJoystick joystick(&net);
SkidSteerVehicle vehicle(&net);

void setup() {
  chuck.begin();
  net.begin(XBEE_BAUD);
  delay(200);
  net.debug("JoySt");
}

void loop() {
  delay(100);
  NetObjectsUpdate update = net.getUpdate();
  if (update.type() == MOTION_SKID_STEER_VEHICLE)
    vehicle = update.skidSteerVehicle();
    
  chuck.update();
  
  joystick.updateFromXY(
    chuck.readJoyX(),
    chuck.readJoyY(),
    chuck.buttonC,
    chuck.buttonZ
  );
  
  joystick.broadcast();
}
